package com.it.mybatis.controller;

import com.it.mybatis.domain.Company;
import com.it.mybatis.model.ApiModel;
import com.it.mybatis.query.CompanyQuery;
import com.it.mybatis.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author LHN
 * @ClassName CompanyController
 * @Date 2021/10/23
 * @Description }
 */
@RestController
public class CompanyController {

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Autowired
    CompanyService companyService;

    @RequestMapping("/getCompany")
    public ApiModel getCompany(){
        return companyService.findAll();
    }

    @RequestMapping("/delete")
    public ApiModel delete(Integer id){
        return companyService.deleteById(id);
    }


    @RequestMapping("/insert")
    public ApiModel insertCompany(Company company){
        return  companyService.insertCompany(company);
    }

    @RequestMapping("/getCompanyBy")
    public ApiModel getCompanyBy(String companyName,String address,String resPeopleName){
        CompanyQuery query = new CompanyQuery();
        query.setCurrentPage(1);
        query.setPageSize(10);
        query.setCompanyName(companyName);
        query.setAddress(address);
        query.setResPeopleName(resPeopleName);
//        query.setCompanyName("n");
//        query.setAddress("成");
//        query.setResPeopleName("任");
        return companyService.findBy(query);
    }
    @RequestMapping("/setRedis")
    public ApiModel getRedis(String key,String value){
        // 从redis中获取值
        stringRedisTemplate.boundValueOps(key).set(value);
        return ApiModel.ok();
    }
    @RequestMapping("/getRedis")
    public ApiModel getRedis(String key){
        // 从redis中获取值
        String value = stringRedisTemplate.boundValueOps(key).get();
        return ApiModel.ok(value);
    }

}
